package com.tencent.sr.iris.basic.saas.dependency;

import com.alibaba.fastjson.JSON;
import com.tencent.sr.iris.basic.service.interfaces.client.IrisCommonKvConfigClient;
import com.tencent.sr.iris.basic.service.interfaces.dto.TCommonKvConfigDTO;
import com.tencent.sr.iris.basic.service.interfaces.request.TCommonKvConfigAddRequest;
import com.tencent.sr.iris.basic.service.interfaces.request.TCommonKvConfigDeleteRequest;
import com.tencent.sr.iris.basic.service.interfaces.request.TCommonKvConfigQueryPageRequest;
import com.tencent.sr.iris.basic.service.interfaces.request.TCommonKvConfigUpdateRequest;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.common.request.PaginationRequest;
import com.tencent.sr.rmall.common.response.PaginationResponse;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author xiaojun
 */
@Component
@Slf4j
public class IrisCommonKvConfigDependency {

    @Resource
    private IrisCommonKvConfigClient irisCommonKvConfigClient;

    public HttpResult<Boolean> add(TCommonKvConfigAddRequest request) {
        try {
            return irisCommonKvConfigClient.add(request);
        } catch (Exception e) {
            log.error("add commonKv config error,request:{}", JSON.toJSONString(request), e);
            return HttpResult.fail(e.getMessage());
        }
    }

    public HttpResult<Boolean> update(TCommonKvConfigUpdateRequest request) {
        try {
            return irisCommonKvConfigClient.update(request);
        } catch (Exception e) {
            log.error("update commonKv config error,request:{}", JSON.toJSONString(request), e);
            return HttpResult.fail(e.getMessage());
        }
    }

    public HttpResult<Boolean> delete(TCommonKvConfigDeleteRequest request) {
        try {
            return irisCommonKvConfigClient.delete(request);
        } catch (Exception e) {
            log.error("delete commonKv config error,request:{}", JSON.toJSONString(request), e);
            return HttpResult.fail(e.getMessage());
        }
    }

    public HttpResult<PaginationResponse<TCommonKvConfigDTO>> queryCommonKVPage(
            PaginationRequest<TCommonKvConfigQueryPageRequest> page) {
        try {
            return irisCommonKvConfigClient.queryCommonKVPage(page);
        } catch (Exception e) {
            log.error("queryCommonKVPage error,request:{}", JSON.toJSONString(page), e);
            return HttpResult.fail(e.getMessage());
        }

    }
}
